package com.summba.common;

import ICTCLAS.I3S.AC.ICTCLAS50;

public class ChinaSegment {
	private ICTCLAS50 instantICTCLAS50;
	
	public ChinaSegment(){
		try{
			instantICTCLAS50 = new ICTCLAS50();
			//分词所需库的路径
			String argu = ".\\conf\\ICTCLAS50";
			//初始化
			if (instantICTCLAS50.ICTCLAS_Init(
					argu.getBytes("utf-8")) == false){
				System.out.println("Init Fail!");
				return ;
			}
			else{ 
				System.out.println("Init Succeed!"); 
			}
			System.out.println("设置词性标注集");
			//设置词性标注集(0 计算所二级标注集，1 计算所一级标注集，
			//2 北大二级标注集，3 北大一级标注集)
			instantICTCLAS50.ICTCLAS_SetPOSmap(1);
			
			//导入用户字典
			int nCount = 0;
			//String usrdir = ".\\conf\\ICTCLAS50\\userdict.txt"; //用户字典路径
			String usrdir = ".\\conf\\ICTCLAS50\\new_csmt_userdict.txt"; //用户字典路径
			
			byte[] usrdirb = usrdir.getBytes();//将string转化为byte类型
			//导入用户字典,返回导入用户词语个数第一个参数为用户字典路径，第二个参数为用户字典的编码类型
			nCount = instantICTCLAS50.ICTCLAS_ImportUserDictFile(usrdirb, 3);
			System.out.println("导入用户词个数" + nCount);
			nCount = 0;
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public String segmentWord(String sInput){
		String sTemp = null;
		try{
			byte nativeBytes[] = instantICTCLAS50.ICTCLAS_ParagraphProcess(
					sInput.getBytes("utf-8"), 3, 0);
			sTemp = new String(nativeBytes, 0, nativeBytes.length, "utf-8");
		}catch( Exception ex){
			ex.printStackTrace();
		}
		return sTemp;
	}
	
	public void exitModular(){
		System.out.println("EXIT ChinaSegment modular!!");
		instantICTCLAS50.ICTCLAS_Exit();
	}

}
